﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Data.GameData
{
    public class ShipSystem : GameObject, ICloneable
    {
        #region Attributes
        /*
  [Name:Sprint Missile]
  [Code:Ga]
  [SL:0]
  [Size:3]
  [Cost:22]
         */
        private string name;
        private string code;
        private int sl;
        private double size;
        private double cost;
        private int modifier;

        private bool isEngine;
        private bool isSensor;
        private bool isLifeSupport;
        private bool isWeapon;
        private bool isPointDefence;

        private bool isDestroyed;
        #endregion

        #region Constructor
        public ShipSystem()
            : base()
        {
        }
        #endregion

        #region Properties
        public string Name
        {
            get { return name; }
        }
        public string Code
        {
            get { return code; }
        }
        public int SL
        {
            get { return sl; }
        }
        public double Size
        {
            get { return size; }
        }
        public double Cost
        {
            get { return cost; }
        }
        public int Modifier
        {
            get { return modifier; }
        }
        public bool IsEngine
        {
            get { return isEngine; }
        }
        public bool IsSensor
        {
            get { return isSensor; }
        }
        public bool IsLifeSupport
        {
            get { return isLifeSupport; }
        }
        public bool IsWeapon
        {
            get { return isWeapon; }
        }
        public bool IsPointDefence
        {
            get { return isPointDefence; }
        }
        public bool IsDestroyed
        {
            get { return isDestroyed; }
            set { isDestroyed = value; }
        }
        #endregion

        #region Public Methods
        public override bool BuildFromMetaData(Common.TokenReader.MetaObject meta)
        {
            base.BuildFromMetaData(meta);

            foreach (string token in meta.TokenList)
            {
                string[] tokens = token.Split(':');

                // Single line Tags
                if (tokens.Count() == 1)
                {
                    switch (tokens[0].ToLower())
                    {
                        case "engine":
                            isEngine = true;
                            break;
                        case "sensor":
                            isSensor = true;
                            break;
                        case "lifeSupport":
                            isLifeSupport = true;
                            break;
                        case "weapon":
                            isWeapon = true;
                            break;
                        case "pointdefence":
                            isPointDefence = true;
                            break;
                    }
                    continue;
                }

                if (tokens[0].ToLower() == "name")
                {
                    name = tokens[1];
                    continue;
                }
                if (tokens[0].ToLower() == "code")
                {
                    code = tokens[1];
                    continue;
                }
                if (tokens[0].ToLower() == "sl")
                {
                    sl = int.Parse(tokens[1]);
                    continue;
                }
                if (tokens[0].ToLower() == "size")
                {
                    size = double.Parse(tokens[1]);
                    continue;
                }
                if (tokens[0].ToLower() == "cost")
                {
                    cost = double.Parse(tokens[1]);
                    continue;
                }
                if (tokens[0].ToLower() == "modifier")
                {
                    modifier = int.Parse(tokens[1]);
                    continue;
                }
            }

            return true;
        }

        public override string ToString()
        {
            if (!isDestroyed)
                return code;
            else
                return "x";
        }
        #endregion

        #region ICloneable Members
        public new object Clone()
        {
            return this.MemberwiseClone();
        }
        #endregion
    }
}
